home *** CD-ROM | disk | FTP | other *** search
/ Programming in Microsoft Windows with C# / Programacion en Microsoft Windows con C#.iso / Original Code / Buttons and Labels and Scrolls (Oh, My!) / SimpleButton / SimpleButton.cs next >
Encoding:
Text File  |  2001-01-15  |  1.1 KB  |  38 lines

  1. //-------------------------------------------
  2. // SimpleButton.cs ⌐ 2001 by Charles Petzold
  3. //-------------------------------------------
  4. using System;
  5. using System.Drawing;
  6. using System.Windows.Forms;
  7.  
  8. class SimpleButton: Form
  9. {
  10.      public static void Main()
  11.      {
  12.           Application.Run(new SimpleButton());
  13.      }
  14.      public SimpleButton()
  15.      {
  16.           Text = "Simple Button";
  17.  
  18.           Button btn   = new Button();
  19.           btn.Parent   = this;
  20.           btn.Text     = "Click Me!";
  21.           btn.Location = new Point(100, 100);
  22.           btn.Click   += new EventHandler(ButtonOnClick);
  23.      }
  24.      void ButtonOnClick(object obj, EventArgs ea)
  25.      {
  26.           Graphics grfx   = CreateGraphics();
  27.           Point    ptText = Point.Empty;
  28.           string   str    = "Button clicked!";
  29.  
  30.           grfx.DrawString(str, Font, new SolidBrush(ForeColor), ptText);
  31.           System.Threading.Thread.Sleep(250);
  32.           grfx.FillRectangle(new SolidBrush(BackColor), 
  33.                new RectangleF(ptText, grfx.MeasureString(str, Font)));
  34.  
  35.           grfx.Dispose();
  36.      }
  37. }
  38.